package com.hyd.hx_adr.utils;

import com.hyd.hx_adr.domain.enums.ResCode;
import com.hyd.hx_adr.domain.entity.JsonResult;

/* *
 * ResultUtils
 * @author AoMing
 * @since  2022/1/1314:58
 * */
public class ResultUtils {

    public static <T> JsonResult<T> success() {
        return new JsonResult<T>().setCode(ResCode.SUCCESS).setMessage("请求成功").setSuccess(true);
    }

    public static <T> JsonResult<T> success(T data) {
        return new JsonResult<T>().setCode(ResCode.SUCCESS).setSuccess(true).setMessage("请求成功").setData(data);
    }

    public static <T> JsonResult<T> success(T data, Long count) {
        return new JsonResult<T>().setData(data).setSuccess(true).setMessage("请求成功").setCount(count).setCode(ResCode.SUCCESS);
    }

    public static <T> JsonResult<T> error(String message) {
        return new JsonResult<T>().setCode(ResCode.ERROR).setMessage(message);
    }

    public static <T> JsonResult<T> response(ResCode code, String message, boolean success) {
        return new JsonResult<T>().setCode(code).setMessage(message).setSuccess(success);
    }

    public static <T> JsonResult<T> response(ResCode code, String message, boolean success, T data) {
        return new JsonResult<T>().setCode(code).setMessage(message).setSuccess(success).setData(data);
    }
}
